/**
 * Created Date: Sunday, April 9th 2023, 10:56:08 pm
 * Author: CodingGorit
 * -----
 * Last Modified: Tue Apr 11 2023
 * Modified By: CodingGorit
 * -----
 * Copyright © 2019 —— 2023 fmin-courses All Rights Reserved
 * ------------------------------------
 * Javascript will save your soul!
 */

import { IPage } from '@/types';
import request from '@/utils/request';

const http = request.getInstance();

const blogApi = {
	BaseBlog: '/content/back/blog',
	ByPage: '/content/back/blog/page',
	BlogDetail: '/content/back/blog/detail',
	TopBlog: '/content//back/blog/top'
}

// 关于相关
const aboutApi = {
	AboutOperate: '/api/v1/content/back/about',
	ByPage: '/api/v1/content/back/about/page'
}

// =======================================================
/**
 * 分页获取 blog 列表
 * @param {Object} page
 */
export function getBlogByPage (page: IPage) {
	return http.request({
		url: blogApi.ByPage,
		method: 'post',
		data: page
	})
}

// 添加帖子
export function addBlog(data: any) {
	return http.request({
		url: blogApi.BaseBlog,
		method: 'post',
        data: data
	})
}

// 修改帖子
export function updateBlog(data: any) {
	return http.request({
		url: blogApi.BaseBlog,
		method: 'put',
        data: data
	})
}

/**
 * 查阅帖子详情
 * @param {Object} id
 */
export function getBlogDetail(id: string) {
	return http.request({
		url: blogApi.BlogDetail + `/${id}`,
		method: 'get'
	})
}

/**
 * 置顶帖子
 */
export function enableBlogTop(state: number, id: string) {
	return http.request({
		url: blogApi.TopBlog + `/${state}/${id}`,
		method: 'put'
	})
}
// =======================================================

/**
 * 添加相关
 * @param {Object} data
 */
export function addAbout<T = unknown>(data: T) {
	return http.request({
		url: aboutApi.AboutOperate,
		method: 'post',
		data: data
	})
}

/**
 * 修改
 * @param {Object} data
 */
export function updateAbout<T = unknown>(data: T) {
	return http.request({
		url: aboutApi.AboutOperate,
		method: 'put',
		data: data
	})
}

/**
 * 根据 ID 获取 about
 * @param {Object} data
 */
export function getAboutById(id: string) {
	return http.request({
		url: aboutApi.AboutOperate + `/${id}`,
		method: 'get'
	})
}

/**
 * 删除about 
 * @param {Object} id
 */
export function deleteAboutById(id: string) {
	return http.request({
		url: aboutApi.AboutOperate + `/${id}`,
		method: 'delete'
	})
}

/**
 * 分页获取
 * @param {Object} page
 */
export function getAboutByPage (page: IPage) {
	return http.request({
		url: aboutApi.ByPage,
		method: 'post',
		data: page
	})
}

/**
 * 启用 关闭 about
 * @param {Object} id
 * @param {Object} enable
 */
export function enableAbout(id: string, enable: number) {
	return http.request({
		url: aboutApi.AboutOperate + `/${id}/${enable}`,
		method: 'put'
	})
}
